local skel = fk.CreateSkill{
  name = "tea__kunyi",
}
Fk:loadTranslationTable{
  ["tea__kunyi"] = "坤仪",
  [":tea__kunyi"] = "当你使用牌指定目标时，你可以令其中一个目标摸一张牌，若其本阶段此前未获得过牌，你摸两张牌。",
  ["#tea__kunyi-invoke"] = "坤仪：你可以令其中一个目标摸一张牌",
  ["tea__kunyi_tip"] = "本阶段未获得过牌",
}
---@type TrigSkelSpec<AimFunc>
local kunyi = {
  anim_type = "drawcard",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skel.name) and player == target and #data:getAllTargets() > 0 and data.firstTarget
  end,
  on_cost = function (self, event, target, player, data)
    local targets = table.filter(data:getAllTargets(), function(p) return not p.dead end)
    local tos = table.filter(targets, function(p)
      local phase_id = player.room.logic:getCurrentEvent():findParent(GameEvent.Phase, true).id
      if not phase_id then return end
      local ret = player.room.logic:getEventsByRule(GameEvent.MoveCards, 1, function (e)
        for _, move in ipairs(e.data) do
          if move.to == p and table.contains({ Card.PlayerHand }, move.toArea) then
            return true
          end
        end
      end, phase_id)
      return #ret == 0
    end)
    local to = player.room:askToChoosePlayers(player, {
      targets = targets,
      min_num = 1,
      max_num = 1,
      skill_name = skel.name,
      prompt = "#tea__kunyi-invoke",
      target_tip_name = skel.name,
      extra_data = table.map(tos, function(p)
        return p.id
      end)
    })[1]
    if to then
      event:setCostData(self, { to = to, tos = tos })
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local to, tos = event:getCostData(self).to, event:getCostData(self).tos
    to:drawCards(1 ,skel.name)
    if not player.dead and table.contains(tos, to) then
      player:drawCards(2, skel.name)
    end
  end
}
Fk:addTargetTip{
  name = skel.name,
  target_tip = function (self, player, to_select, selected, selected_cards, card, selectable, extra_data)
    local tos = extra_data.extra_data or {}
    if table.contains(tos, to_select.id) then
      return "tea__kunyi_tip"
    end
  end
}
skel:addEffect(fk.TargetSpecifying, kunyi)
-- Fk.generals["mouxusheng"]:addSkill(skel.name)
return skel